//
//  sssView.swift
//  XXIOT
//
//  Created by xx on 2024/8/22.
//

import UIKit
import FastSwiftSDK

// 开关view
class RelayView: FastView {
    
    private lazy var lbl_state : FastLabel = {
        let lbl = FastLabel.init(text: "正常",font: .system(11), color: color_green)
        self.addSubview(lbl)
        return  lbl
    } ()
    
    private lazy var lbl_name : FastLabel = {
        let lbl = FastLabel.init(text: "开关",font: .bold(17), color: .x333)
        lbl.textAlignment = .center
    
        self.addSubview(lbl)
        return  lbl
    } ()
    
    private lazy var btn_switch : FastButton = {
        let btn =  FastButton.init(title: "", imgName: "switch_off",color: .white ,font:UIFont.system(15));
        self.addSubview(btn)
        return  btn
    } ()
    
    func set(with data:Dictionary<String,Any>) {
        if data.int("state") == 1{
            lbl_state.text = "正常"
            lbl_state.textColor = color_green
        }else{
            lbl_state.text = "离线"
            lbl_state.textColor = color_red
        }
        if data.string("data") == "ON"{
            btn_switch.image = kImage("switch_on")
            btn_switch.tag = 1
        }else{
            btn_switch.image = kImage("switch_off")
            btn_switch.tag = 0
        }
        var name = data.string("remark")
        if name == nil{
            name = data.string("name")
        }
        lbl_name.text = name
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        lbl_state.snp.makeConstraints { make in
            make.left.top.equalTo(15)
        }
        btn_switch.snp.makeConstraints { make in
            make.size.equalTo(80)
            make.center.equalToSuperview()
        }
        lbl_name.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.right.bottom.equalTo(-20)
        }
    }
}
